/******************************************************************************
*
* MODULE:    CuentaUnos.v
* DEVICE:     
* PROJECT:   Tarea 1 Diseño Electronico Digital
* AUTHOR:    Ricardo Dávila Castro   
* DATE:      2010 19:35:08
*
* ABSTRACT:  Contador de Unos Ejercicio 3
*            
*******************************************************************************/

`ifndef 	CUENTA_UNOS
`define    CUENTA_UNOS

module CuentaUnos(clk, data_in, start, count, done);
	input clk;
	input [7:0] data_in;
	input start;
	output [3:0] count;
	output done =0;
	reg done =0;
	reg [7:0] data=0;
	reg [3:0] iterat =0;
	reg [3:0] cont_int=0;

//assign cont_int = start ? 'b0000 : 'b0000 ;

always @(posedge clk)
begin
	if (start)
	begin 
		iterat <= 'b0000;
		done <= 'b0;
		data <= data_in;
	end
	if (iterat[3])
	begin 
		done <= 'b1;
		iterat <= 'b0000;
		cont_int <= 'b0000;
	end
	else 
	begin 
		if (data [iterat] == 1) 
			cont_int <= cont_int + 1;
			else
			cont_int <= cont_int ;
			
			iterat <= iterat + 1; // se mueve el inidice del arreglo
	end
end
assign count = cont_int;
endmodule
`endif